# 使用pytest未通过时，比如定义的函数如下：
"""
def get_formatted_name(first, middle, last):
    # 生成格式规范的姓名
    full_name = f"{first} {middle} {last}"
    return full_name.title()
"""
# 由于在测试文件中调用get_formatted_name()这个测试函数时，并没有给这个函数传以足够的参数
# 此时在terminal 窗口中输入pytest，会报出类型错误，类型错误显示如下：
# test_name_function.py F                                                                                            [100%]
#
# ======================================================= FAILURES ========================================================
# _________________________________________________ test_first_last_name __________________________________________________
#
#     def test_first_last_name():
#         """能够正确地处理像 Janis Joplin 这样的姓名吗？"""
# >       formatted_name = get_formatted_name('Janis', 'Joplin')
# E       TypeError: get_formatted_name() missing 1 required positional argument: 'last'
#
# test_name_function.py:13: TypeError
# ================================================ short test summary info ================================================
# FAILED test_name_function.py::test_first_last_name - TypeError: get_formatted_name() missing 1 required positional argument: 'last'
# =================================================== 1 failed in 0.08s ===================================================


# 此时应该做的是修改测试文件中测试函数内部调用的函数的定义，而不是让传入的参数变多
def get_formatted_name(first, last, middle=''):
    """生成格式规范的姓名"""
    if middle:
        full_name = f"{first} {middle} {last}"
    else:
        full_name = f"{first} {last}"
    return full_name.title()
